package com.msc.mc.service.impl;

import org.apache.log4j.Logger;

import com.msc.mc.httpClient.HttpClient;
import com.msc.sdm.ic.pub.SimMgrDbObject;
/**
 * 
 * @author sdmadm
 *
 */
public class NIOServiceImpl  {

	private static Logger log = Logger.getLogger(HttpClient.class);

	 

	public static String sendMessage(SimMgrDbObject dbObject, String action) {
		log.info("start send message ....");

		try {
			if (dbObject != null) {
				String sid = dbObject.getObjectType();
				log.info("send " + sid + " messageType.");
				String response = null;
				//HttpClient httpClient = new HttpClient();
				String sbParams = "id=" + dbObject.getId() + "&action=" + action + "&type=" + dbObject.getObjectType();
				try {
					//response = httpClient.sendPost(sbParams);
					HttpClient httpClient = new HttpClient(sbParams);
					response = httpClient.sendPost(sbParams);
				} catch (Exception e) {
					e.printStackTrace();
				}
				System.out.println("---------------->>>>>>>>   response:" + response);
				if ("0000".equals(response)) {
					log.info("send " + sid + " messageType Success.");
					return "0000";
				} else {
					log.error("send " + sid + " messageType Fail.");
				}

			} else {
				log.error("Please input  SimMgrDbObject.");
				log.error("send message Fail.");
			}
		} catch (Exception ex) {
			ex.printStackTrace();
			log.error("send message Fail.");
			return "500";
		}

		return "500";
	}

	public static String sendMessage(String id, String type, String action) {
System.out.println( "-------.>" + type );	
		if( "Full".equals( type ) ) {
			String response = null;
			//HttpClient httpClient = new HttpClient();
			String sbParams = "id=&action=" + action + "&type=" + type;
			try {
				//response = httpClient.sendPost(sbParams);
				HttpClient httpClient = new HttpClient(sbParams);
				httpClient.start();
			} catch (Exception e) { 
				e.printStackTrace(); 
			}

			if ("0000".equals(response)) {
				log.info("send " + type + " messageType Success.");
				return "0000";
			} else {
				//log.error("send " + type + " messageType Fail.");
			}
		}else if (id != null && type != null && action != null) {
			String response = null;
			HttpClient httpClient = new HttpClient();
			String sbParams = "id=" + id + "&action=" + action + "&type=" + type;
			try {
				response = httpClient.sendPost(sbParams);
			} catch (Exception e) { 
				e.printStackTrace();
			}

			if ("0000".equals(response)) {
				log.info("send " + type + " messageType Success.");
				return "0000";
			} else {
				log.error("send " + type + " messageType Fail.");
			}
		}
		return "500";
	}

}
